package cn.sumpay.servlet;

import static cn.sumpay.utils.DataSourceUtil.*;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/1/5.
 */
public class Chart extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Connection connection = getConnection();
        List list = new ArrayList();
        try {
            PreparedStatement pst = connection.prepareStatement("select active_id,awards_id,awards_type from vote_awards_info where active_id = (select active_id from VOTE_ACTIVE where active_state =1)");
            ResultSet rs = pst.executeQuery();
            while(rs.next()){
                Map map = new HashMap();
                String active_id = rs.getString("active_id");
                String awards_id = rs.getString("awards_id");
                String awards_type = rs.getString("awards_type");
                map.put("active_id",active_id);
                map.put("awards_id",awards_id);
                map.put("awards_type",awards_type);
                list.add(map);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.setAttribute("list",list);

        request.getRequestDispatcher("/WEB-INF/jsps/chart.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}